﻿#include "FITKAbaqusAdaptorOutputField.h"
#include "InpKeyLineSpliter.h"
#include "FITKAbaqusINPReader.h"
#include "FITKAbaqusINPWriter.h"
#include "FITK_Kernel/FITKCore/FITKEnumTransformer.hpp"
#include "FITK_Component/FITKAbaqusData/FITKDataCase.h"
#include "FITK_Component/FITKAbaqusData/FITKAbaqusPart.h"
#include "FITK_Interface/FITKInterfaceStructural/FITKAbaAssembly.h"
#include "FITK_Interface/FITKInterfaceStructural/FITKAbaFieldOutput.h"
#include "FITK_Interface/FITKInterfaceStructural/FITKAbaTimePointsManager.h"
#include "FITK_Interface/FITKInterfaceModel/FITKModelSet.h"
#include "FITK_Interface/FITKInterfaceModel/FITKComponentManager.h"
#include <QDebug>
//set集合每行不得超过16个，INP准则
#define SETCOUNT 16

//命名空间
namespace IO
{
	QString FITKAbaqusAdaptorOutputField::getAdaptorClass()
	{
		return "IO::FITKAbaqusAdaptorOutputField";
	}

	void FITKAbaqusAdaptorOutputField::setCaseData(AbaqusData::FITKDataCase* caseData)
	{
		_caseData = caseData;
		tool.setCaseData(caseData);
	}

	void FITKAbaqusAdaptorOutputField::setStepData(Interface::FITKAbaAbstractStep * stepData)
	{
		if (stepData == nullptr) return;
		_stepData = stepData;
		//判断类型是否为显示分析
		_isExplicit = stepData->getStepType() == Interface::FITKAbaAbstractStep::FITKAbaStepType::DynamicExplicit;
	}

	bool FITKAbaqusAdaptorOutputField::adaptR()
	{
		_outputData = dynamic_cast<Interface::FITKAbaFieldOutput*>(_dataObj);
		if (!_outputData || !_reader || !_caseData) return false;
		//校验信息
		//QString line = _reader->previousLine();
		//if (!line.toLower().contains("output")) return false;
		//回退一行 处理关键字信息 
		_reader->backLine();
		//_outputData->setDataObjectName(QString::number(_outputData->getCreatedStep()));
		////互斥参数的最后一个 其余两个为field、history
		//QString diagnostics = s["diagnostics"];
		////共同的可选参数
		//QString matName = s["name"];
		//_outputData->setDataObjectName(matName);
		////Standard下的可选参数
		//QString frequency = s["frequency"];
		//QString modeList = s["mode list"];
		//QString numberInterval = s["number interval"];
		//QString timeMarks = s["time marks"];
		//QString timePoints = s["time points"];
		bool isR, isV;
		while (!_reader->atEnd())
		{
			QString line = _reader->readLine();
			//退出条件
			if (line.startsWith("**") || !line.toLower().contains("output") || line.toLower().contains("history")) return true;
			isR = false;
			isV = false;
			InpKeyLineSpliter s(line, _reader);
			QString sH = s.getHeader().toLower();
			if (s.hasKey("field"))
			{
				//isR = _isExplicit ? readExplicitField() : readStandardField();
				isR = readExplicitField();
			}
			else if (sH == "node output")
			{
				isV = isR = readNodeOutput(line);
			}
			else if (sH == "contact output")
			{
				isV = isR = readContactOutput(line);
			}
			else if (sH == "element output")
			{
				isV = isR = readElementOutput(line);
			}
			else if (sH == "integrated output")
			{
				//isR = readIntegratedOutput(line);暂时没有此关键字
			}
			else if (sH == "incrementation output")
			{
				isV = isR = readIncrementationOutput(line);
			}
			else
			{
				_reader->consoleMessage(3, QString("Key Error : %1 File:%2 Line:%3").arg(sH).arg(__FILE__).arg(__LINE__));
				return false;
			}

			if (!isR)
			{
				_reader->consoleMessage(3, QString("Read Output Error ,%1 File:%2 Line:%3").arg(sH).arg(__FILE__).arg(__LINE__));
				return false;
			}

			//跳出条件 读取时拆分output
			if (isV)
				return true;
		}
		return isR;
	}

	bool FITKAbaqusAdaptorOutputField::adaptW()
	{
		_outputData = dynamic_cast<Interface::FITKAbaFieldOutput*>(_dataObj);
		if (!_outputData || !_writer || !_caseData) return false;
		bool isW = true;

		isW &= writeExplicitField();

        //variable
        auto v = _outputData->getSelectMode();
        QString variable = getVariableString(v);
        bool wOutput = !variable.isEmpty() && _outputData->getDomain() == Interface::FITKAbaOutputVariable::OutputDomain::WholeModel;

		if (!wOutput)
		{
			isW &= writeNodeOutput();
			isW &= writeElementOutput();
			isW &= writeContactOutput();
			//isW &= writeIntegratedOutput();
			isW &= writeIncrementationOutput();
		}
		//写出
		return isW;
	}

	bool FITKAbaqusAdaptorOutputField::readContactOutput(QString line)
	{
		//关键字验证
		if (!line.toLower().startsWith("*contact output")) return false;
		InpKeyLineSpliter s(line, _reader);
		//Explicit类型 Standard类型 共有参数
		QString variable = s["variable"];
		//Standard可选参数
		QString master = s["master"];
		QString nset = s["nset"];
		QString slave = s["slave"];
		QString surface = s["surface"];
		_outputData->clearVariables();
		//输出变量
		_outputData->setSelectMode(getSelectedMode(variable), _outputData->getCreatedStep());

		//暂定一定会有此行
		QString dataline = _reader->readLine();
		if (dataline.startsWith("*"))return false;
		auto pv = dataline.split(',');

		for (int i = 0; i < pv.size(); ++i)
		{
			_outputData->appendVariable(pv[i].trimmed());
		}
		return true;
	}

	bool FITKAbaqusAdaptorOutputField::readElementOutput(QString line)
	{
		//关键字验证
		if (!line.toLower().startsWith("*element output")) return false;
		InpKeyLineSpliter s(line, _reader);
		//共有参数
		QString variable = s["variable"];
		QString rebar = s["rebar"];
		//可选参数
		bool isAallsectionpts = s.hasKey("allsectionpts");
		QString directions = s["directions"];
		QString elset = s["elset"];
		bool isExterior = s.hasKey("exterior");
		QString micromechanics = s["micromechanics"];
		QString position = s["position"];

		if (position == "CENTROIDAL")
		{

		}
		else if (position == "NODES")
		{

		}
		//作用域
		this->setDomain(Interface::FITKModelEnum::FITKModelSetType::FMSElem, elset, isExterior);
		_outputData->clearVariables();
		//输出变量
		_outputData->setSelectMode(getSelectedMode(variable), _outputData->getCreatedStep());

		//设置是否包括可用的局部坐标方向
		_outputData->setIncludeLocalCoordDirWhenAvailable(directions.size() == 3);

		//读取变量并添加
		while (!_reader->atEnd())
		{
			if (_outputData->getSelectMode() !=
				Interface::FITKAbaOutputVariable::OutputVariablesSelectMode::SelectFromListBelow) return true;
			QString dataLine = _reader->readLine();
			if (dataLine.startsWith("*"))
			{
				_reader->backLine();
				return true;
			}
			auto pv = dataLine.split(',');
			if (pv.size() < 1) return false;
			for (int i = 0; i < pv.size(); ++i)
			{
				_outputData->appendVariable(pv[i].trimmed());
			}
		}
		return false;
	}

	bool FITKAbaqusAdaptorOutputField::readNodeOutput(QString line)
	{
		//关键字验证
		if (!line.toLower().startsWith("*node output")) return false;
		InpKeyLineSpliter s(line, _reader);
		//共有参数 
		QString variable = s["variable"];
		//可选参数
		bool isExterior = s.hasKey("exterior");
		QString nset = s["nset"];
		QString tracerSet = s["tracer set"];

		//作用域
		this->setDomain(Interface::FITKModelEnum::FITKModelSetType::FMSNode, nset, isExterior);
		_outputData->clearVariables();
		//输出变量
		_outputData->setSelectMode(getSelectedMode(variable), _outputData->getCreatedStep());

		//读取变量并添加
		while (!_reader->atEnd())
		{
			if (_outputData->getSelectMode() !=
				Interface::FITKAbaOutputVariable::OutputVariablesSelectMode::SelectFromListBelow) return true;
			QString dataLine = _reader->readLine();
			if (dataLine.startsWith("*"))
			{
				_reader->backLine();
				return true;
			}
			auto pv = dataLine.split(',');
			if (pv.size() < 1) return false;
			for (int i = 0; i < pv.size(); ++i)
			{
				_outputData->appendVariable(pv[i].trimmed());
			}
		}
		return false;
	}

	bool FITKAbaqusAdaptorOutputField::readIntegratedOutput(QString line)
	{
		//关键字验证
		if (!line.toLower().startsWith("*integrated output")) return false;
		InpKeyLineSpliter s(line, _reader);
		//共有参数
		QString variable = s["variable"];
		//互斥参数
		QString section = s["section"];
		QString surface = s["surface"];
		QString elset = s["elset"];

		if (!section.isEmpty())
		{
			//暂不支持
		}
		else if (!surface.isEmpty())
		{
			//暂不支持
		}
		else if (!elset.isEmpty())
		{
			//作用域
			this->setDomain(Interface::FITKModelEnum::FITKModelSetType::FMSElem, elset, false);
		}
		else
		{
			//error
		}

		//输出变量
		_outputData->setSelectMode(getSelectedMode(variable), _outputData->getCreatedStep());

		//读取变量并添加
		while (!_reader->atEnd())
		{
			if (_outputData->getSelectMode() !=
				Interface::FITKAbaOutputVariable::OutputVariablesSelectMode::SelectFromListBelow) return true;
			QString dataLine = _reader->readLine();
			if (dataLine.startsWith("*"))
			{
				_reader->backLine();
				return true;
			}
			auto pv = dataLine.split(',');
			if (pv.size() < 1) return false;
			for (int i = 0; i < pv.size(); ++i)
			{
				_outputData->appendVariable(pv[i].trimmed());
			}
		}
		return false;
	}

	bool FITKAbaqusAdaptorOutputField::readStandardField()
	{
		QString line = _reader->previousLine();
		if (!line.toLower().startsWith("*output")) return false;
		//关键字处理
		InpKeyLineSpliter s(line, _reader);

		QString op = s["op"];
		QString timeInterval = s["time interval"];
		QString variable = s["variable"];

		if (!timeInterval.isEmpty())
		{
			int intervalNumber = timeInterval.toInt();
			_outputData->setIntervals(intervalNumber);
		}


		if (variable == "PRESELECT")
		{
			_outputData->setSelectMode(Interface::FITKAbaOutputVariable::OutputVariablesSelectMode::PreselectedDefaults);
		}
		else if (variable == "ALL")
		{
			_outputData->setSelectMode(Interface::FITKAbaOutputVariable::OutputVariablesSelectMode::All);
		}
		else if (!variable.isEmpty())
		{
			_reader->consoleMessage(3, "Read Field Output Error " + variable);
			return false;
		}

		return true;
	}

	bool FITKAbaqusAdaptorOutputField::readExplicitField()
	{
		QString line = _reader->previousLine();
		if (!line.toLower().startsWith("*output")) return false;
		//关键字处理
		InpKeyLineSpliter s(line, _reader);

		QString numberInterval = s["number interval"];
		QString timePoints = s["time points"];

		QString timeMarks = s["time marks"]; //定时 精确时间的输出
		//共用参数
		QString filter = s["fikter"];
		QString op = s["op"];
		QString variable = s["variable"];
		QString timeInterval = s["time interval"];

		//频率
		if (timeInterval.contains('.'))
		{
			_outputData->setOutputFrequency(Interface::FITKAbaOutputVariable::OutputFrequency::EvertyXUnitsOfTime);
			double xUnits = timeInterval.toDouble();
			_outputData->setXUnitsOfTime(xUnits);
		}
		else if (!timeInterval.isEmpty())
		{
			_outputData->setOutputFrequency(Interface::FITKAbaOutputVariable::OutputFrequency::EveryTimeIncrement);
		}
		else if (!timePoints.isEmpty())
		{
			_outputData->setOutputFrequency(Interface::FITKAbaOutputVariable::OutputFrequency::FromTimePoints);
			int id = -1;
			if (!getTimePointNameByID(timePoints, id))
			{
				_reader->consoleMessage(3, QString("Read FieldOutput Error, Get TimePoints Error, TimePointsName : %1").arg(timePoints));
				return false;
			}
			_outputData->setTimePointsId(id);
		}
		else
		{
			_outputData->setOutputFrequency(Interface::FITKAbaOutputVariable::OutputFrequency::EvenlySpacedTimeIntervals);
			int intervalNumber = numberInterval.toInt();
			//默认值
			if (numberInterval.isEmpty()) intervalNumber = 20;
			_outputData->setIntervals(intervalNumber);
		}

		//设置定时类型
		if (timeMarks == "YES")
		{
			_outputData->setOutputTiming(Interface::FITKAbaOutputVariable::OutputTiming::OutputAtExactTimes);
		}

		//输出变量
		if (!variable.isEmpty())
			_outputData->setSelectMode(getSelectedMode(variable), _outputData->getCreatedStep());
		return true;
	}

	//增量输出
	bool FITKAbaqusAdaptorOutputField::readIncrementationOutput(QString line)
	{
		//关键字验证
		if (!line.toLower().startsWith("*Incrementation Output")) return false;

		//关键字处理
		InpKeyLineSpliter s(line, _reader);
		//参数列表
		QString variable = s["variable"];
		//输出变量
		_outputData->setSelectMode(getSelectedMode(variable), _outputData->getCreatedStep());

		//读取变量并添加
		while (!_reader->atEnd())
		{
			if (_outputData->getSelectMode() !=
				Interface::FITKAbaOutputVariable::OutputVariablesSelectMode::SelectFromListBelow) return true;
			QString dataLine = _reader->readLine();
			if (dataLine.startsWith("*"))
			{
				_reader->backLine();
				return true;
			}
			auto pv = dataLine.split(',');
			if (pv.size() < 1) return false;
			for (int i = 0; i < pv.size(); ++i)
			{
				_outputData->appendVariable(pv[i].trimmed());
			}
		}
		return false;
	}

	bool FITKAbaqusAdaptorOutputField::writeStandardField()
	{
		auto stream = _writer->getStream();
		if (stream == nullptr) return false;

		*stream << "*Output, field";

		if (_outputData->getSelectMode() ==
			Interface::FITKAbaOutputVariable::OutputVariablesSelectMode::PreselectedDefaults)
		{
			*stream << QString(",variable=%1").arg("PRESELECT");
		}
		else if (_outputData->getSelectMode() ==
			Interface::FITKAbaOutputVariable::OutputVariablesSelectMode::All)
		{
			*stream << QString(",variable=%1").arg("ALL");
		}


		return false;
	}

	bool FITKAbaqusAdaptorOutputField::writeExplicitField()
	{
		bool isW = true;
		QString output;
		// 写出函数主体
		QTextStream* stream = _writer->getStream();
		if (stream == nullptr) return false;
		output += "*Output, field";
		//variable
		auto v = _outputData->getSelectMode();

		QString variable = getVariableString(v);

		if (!variable.isEmpty() && _outputData->getDomain() == Interface::FITKAbaOutputVariable::OutputDomain::WholeModel)
			output += QString(", %1").arg(variable);

		//interval
		if (_outputData->getOutputFrequency() == Interface::FITKAbaOutputVariable::OutputFrequency::EvenlySpacedTimeIntervals)
		{
			//20是默认值
			if (_outputData->getIntervals() != 20)
			{
				QString strInterval = _writer->int2String(_outputData->getIntervals(), 0);
				output += QString(", number interval=%1").arg(strInterval);
			}
		}
		//每x时间增量
		else if (_outputData->getOutputFrequency() == Interface::FITKAbaOutputVariable::OutputFrequency::EvertyXUnitsOfTime)
		{
			QString x = _writer->double2String(_outputData->getXUnitsOfTime(), 9, 0);
			output += QString(", time interval=%1").arg(x);
		}
		//每一时间增量
		else if (_outputData->getOutputFrequency() == Interface::FITKAbaOutputVariable::OutputFrequency::EveryTimeIncrement)
		{
			output += QString(", time interval=1e-100");
		}
		else if (_outputData->getOutputFrequency() == Interface::FITKAbaOutputVariable::OutputFrequency::FromTimePoints)
		{
			QString timePointName;
			if (!getTimePointIDByName(_outputData->getTimePointsId(), timePointName))
			{
				_writer->consoleMessage(3, QString("Write FieldOutput Error, TimePoints Write Error, FieldOutputName : %1").arg(_outputData->getDataObjectName()));
				return false;
			}
			output += QString(", time points=%1").arg(timePointName);
		}

		//输出定时类型 默认不输出则为近似值
		if (_outputData->getOutputTiming() == Interface::FITKAbaOutputVariable::OutputTiming::OutputAtExactTimes)
		{
			output += QString(", time marks=YES");
		}
		//关键字判断如果和上一个关键字重复并且参数一致，则省略该字段
		//if (_outputData->objectName() != output)
		//{
		*stream << output << endl;
		//用output的行字符串作为名字 与上个写出的output做唯一性检测
		//_outputData->setObjectName(output);
		//}

		return isW;
	}

	bool FITKAbaqusAdaptorOutputField::writeContactOutput()
	{
		////共有参数
		//QString nset = s["nset"];
		//QString tracerSet = s["tracer set"];
		// 写出函数主体
		QTextStream* stream = _writer->getStream();
		if (stream == nullptr) return false;

		QString outputString;
		QString nsetName;
		QString variable = getVariableString(_outputData->getSelectMode());

		auto setObj = _outputData->getComponentObj();
		auto modelObj = _outputData->getModelObj();
		nsetName = getSetName(setObj, modelObj);

		outputString += "*Contact Output";
		if (_outputData->getExteriorOnly())
			outputString += ", exterior";
		else if (_outputData->getComponentID() != 0 && !nsetName.isEmpty())
			outputString += QString(", nset=%1").arg(nsetName);

		if (!variable.isEmpty())
			outputString += QString(", %1").arg(variable);

		auto varList = _outputData->getSelectedContactVaraiables();
		if (varList.size() > 0)
			*stream << outputString << endl;
		if (isSelectedModelWrite(_outputData->getSelectMode()))
			_writer->writeLineData(varList);
		return true;
	}

	bool FITKAbaqusAdaptorOutputField::writeElementOutput()
	{
		////共有参数
		//QString nset = s["nset"];
		//QString tracerSet = s["tracer set"];
		// 写出函数主体
		QTextStream* stream = _writer->getStream();
		if (stream == nullptr) return false;

		QString outputString;
		QString elsetName;
		QString variable = getVariableString(_outputData->getSelectMode());

		auto setObj = _outputData->getComponentObj();
		auto modelObj = _outputData->getModelObj();
		elsetName = getSetName(setObj, modelObj);

		outputString += "*Element Output";
		if (_outputData->getExteriorOnly())
			outputString += ", exterior";
		else if (_outputData->getComponentID() != 0 && !elsetName.isEmpty())
			outputString += QString(", elset=%1").arg(elsetName);

		if (_outputData->getIncludeLocalCoordDirWhenAvailable())
			outputString += QString(", directions=YES");

		if (!variable.isEmpty())
			outputString += QString(", %1").arg(variable);

		auto varList = _outputData->getSelectedElementVariables();
		if (varList.size() > 0)
			*stream << outputString << endl;
		if (isSelectedModelWrite(_outputData->getSelectMode()))
			_writer->writeLineData(varList);
		return true;
	}

	bool FITKAbaqusAdaptorOutputField::writeNodeOutput()
	{
		////共有参数
		//QString nset = s["nset"];
		//QString tracerSet = s["tracer set"];
		// 写出函数主体
		QTextStream* stream = _writer->getStream();
		if (stream == nullptr) return false;

		QString outputString;
		QString nsetName;
		QString variable = getVariableString(_outputData->getSelectMode());

		auto setObj = _outputData->getComponentObj();
		auto modelObj = _outputData->getModelObj();
		nsetName = getSetName(setObj, modelObj);

		outputString += "*Node Output";
		if (_outputData->getExteriorOnly())
			outputString += ", exterior";
		else if (_outputData->getComponentID() != 0 && !nsetName.isEmpty())
			outputString += QString(", nset=%1").arg(nsetName);

		if (!variable.isEmpty())
			outputString += QString(", %1").arg(variable);

		auto varList = _outputData->getSelectedNodalVariables();
		if (varList.size() > 0)
			*stream << outputString << endl;
		if (isSelectedModelWrite(_outputData->getSelectMode()))
			_writer->writeLineData(varList);
		return true;
	}

	bool FITKAbaqusAdaptorOutputField::writeIntegratedOutput()
	{
		QTextStream* stream = _writer->getStream();
		if (stream == nullptr) return false;

		QString outputString;
		QString elsetName;
		QString variable = getVariableString(_outputData->getSelectMode());

		outputString += "*Integrated Output";

		auto setObj = _outputData->getComponentObj();
		auto modelObj = _outputData->getModelObj();
		elsetName = getSetName(setObj, modelObj);

		if (_outputData->getComponentID() != 0 && !elsetName.isEmpty())
			outputString += QString(", elset=%1").arg(elsetName);

		if (!variable.isEmpty())
			outputString += QString(", %1").arg(variable);

		auto varList = _outputData->getSelectedContactVaraiables();
		if (varList.size() > 0)
			*stream << outputString << endl;
		if (isSelectedModelWrite(_outputData->getSelectMode()))
			_writer->writeLineData(varList);
		return true;
	}

	bool FITKAbaqusAdaptorOutputField::writeIncrementationOutput()
	{
		QTextStream* stream = _writer->getStream();
		if (stream == nullptr) return false;

		QString outputString;
		QString variable = getVariableString(_outputData->getSelectMode());

		outputString += "*Incrementation Output";

		if (!variable.isEmpty())
			outputString += QString(", %1").arg(variable);

		auto varList = _outputData->getSelectedIncrementationVariables();
		if (varList.size() > 0)
			*stream << outputString << endl;
		if (isSelectedModelWrite(_outputData->getSelectMode()))
			_writer->writeLineData(varList);
		return true;
	}

	bool FITKAbaqusAdaptorOutputField::isSelectedModelWrite(Interface::FITKAbaOutputVariable::OutputVariablesSelectMode mode)
	{
		switch (mode)
		{
		case Interface::FITKAbaOutputVariable::OutputVariablesSelectMode::SelectFromListBelow:
			return true;
		case Interface::FITKAbaOutputVariable::OutputVariablesSelectMode::PreselectedDefaults:
			return false;
		case Interface::FITKAbaOutputVariable::OutputVariablesSelectMode::All:
			return false;
		case Interface::FITKAbaOutputVariable::OutputVariablesSelectMode::EditVariables:
			return true;
		}
		return false;
	}

	Interface::FITKAbaOutputVariable::OutputVariablesSelectMode FITKAbaqusAdaptorOutputField::getSelectedMode(QString variable)
	{
		if (variable == "PRESELECT")
		{
			return Interface::FITKAbaOutputVariable::OutputVariablesSelectMode::PreselectedDefaults;
		}
		else if (variable == "ALL")
		{
			return Interface::FITKAbaOutputVariable::OutputVariablesSelectMode::All;
		}
		else if (variable.isEmpty())
		{
			return Interface::FITKAbaOutputVariable::OutputVariablesSelectMode::SelectFromListBelow;
		}
		else
		{
			//错误异常 避免写出的时候调用
			if (_reader == nullptr) return Interface::FITKAbaOutputVariable::OutputVariablesSelectMode::EditVariables;
			_writer->consoleMessage(3, QString("Read Field Output Error,%1 File:%2 Line:%3").arg(variable).arg(__FILE__).arg(__LINE__));

		}
		return Interface::FITKAbaOutputVariable::OutputVariablesSelectMode::EditVariables;
	}

	QString FITKAbaqusAdaptorOutputField::getVariableString(Interface::FITKAbaOutputVariable::OutputVariablesSelectMode typeModel)
	{
		QString variable;
		if (typeModel == Interface::FITKAbaOutputVariable::OutputVariablesSelectMode::SelectFromListBelow)
			variable = "";
		else if (typeModel == Interface::FITKAbaOutputVariable::OutputVariablesSelectMode::PreselectedDefaults)
			variable = "variable=PRESELECT";
		else if (typeModel == Interface::FITKAbaOutputVariable::OutputVariablesSelectMode::All)
			variable = "variable=ALL";
		else if (typeModel == Interface::FITKAbaOutputVariable::OutputVariablesSelectMode::EditVariables)
			variable = "";
		return variable;
	}

	bool FITKAbaqusAdaptorOutputField::setDomain(Interface::FITKModelEnum::FITKModelSetType type, QString str, bool isExterior)
	{
		bool isOK = false;

		//nset 或者 elset
		if (type != Interface::FITKModelEnum::FITKModelSetType::FMSNone && !str.isEmpty())
		{
			int modelID = -1;
			int setID = tool.getSetIDByName(str, type, modelID);
			if (setID < 1) return false;

			//查询名字为 elset的ID 需要获取set管理器
			_outputData->setModel(modelID);
			_outputData->setComponent(setID);
			_outputData->setDomain(Interface::FITKAbaOutputVariable::OutputDomain::Set);
			isOK = true;
		}
		else//整个模型
		{
			_outputData->setDomain(Interface::FITKAbaOutputVariable::OutputDomain::WholeModel);
			//是否仅限于外部
			_outputData->setExteriorOnly(isExterior);
			isOK = true;
		}

		return isOK;
	}

	bool FITKAbaqusAdaptorOutputField::getTimePointNameByID(QString name, int& timePointID)
	{
		auto timePointManager = _caseData->getTimePointsManager();
		auto timePointObject = timePointManager->getDataByName(name);
		if (!timePointObject) return false;
		timePointID = timePointObject->getDataObjectID();
		return true;
	}

	bool FITKAbaqusAdaptorOutputField::getTimePointIDByName(int ID, QString & name)
	{
		auto timePointManager = _caseData->getTimePointsManager();
		auto timePointObject = timePointManager->getDataByID(ID);
		if (!timePointObject) return false;
		name = timePointObject->getDataObjectName();
        name = name.contains(' ') ? QString("\"%1\"").arg(name) : name;
		return true;
	}

	QString FITKAbaqusAdaptorOutputField::getSetName(Interface::FITKAbstractModelComponent * comp, Interface::FITKAbstractModel * model)
	{
        QString setName;
        auto setObj = _outputData->getComponentObj();
        if (!setObj) return setName;
        setName = setObj->getDataObjectName();
        setName = setName.contains(' ') ? QString("\"%1\"").arg(setName) : setName;
        auto modelObj = _outputData->getModelObj();
        if (modelObj &&
            setObj->getAbstractModel()->getAbsModelType() == Interface::FITKModelEnum::AbsModelType::AMTMIX &&
            modelObj->getAbsModelType() == Interface::FITKModelEnum::AbsModelType::AssInstance
            )
        {
            QString name = modelObj->getDataObjectName();
            name = name.contains(' ') ? QString("\"%1\"").arg(name) : name;
            setName = name + "." + setName;
        }
        return setName;
	}
}
